<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../../js/vue.js"></script>
    <script src="../../js/vue-router.js"></script>
</head>

<body>



    <div id="app">
        <router-link to="/user/1">User1</router-link>
        <router-link to="/user/2">User2</router-link>
        <router-link to="/user/3">User3</router-link>
        <router-view></router-view>
    </div>

    <script>
        const User = {
            // 虽然有id这个属性，但是在配置路由规则时没有在props中带伤id属性，所以在组件中是接收不到id的
            props: ['id','name', 'age'],
            template: '<h1>user{{ id }}组件信息--name:{{ name }}---age:{{ age }}</h1>'
        }

        var router = new VueRouter({
            routes: [
                // 如果props是一个对象，它会被按原样设置为组件属性
                { path: '/user/:id', component: User, props: {name: 'lisi', age: 20} }
            ]
        })

        var vm = new Vue({
            el: '#app',
            router: router
        })
    </script>
</body>

</html>